package com.xiaoshuidi.cloud.module.contract.enums.contract;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 业主合同状态
 * private String contractStatus;
 *
 * @author 合房源码
 */
@Getter
@AllArgsConstructor
public enum ContractOwnerStatusEnum {

    PENDING("pending", "待审批"),
    REJECT("reject", "审批驳回"),
    NO_SIGNED("no_signed", "待签约"),
    WAITING_ACTIVE("waiting_active", "待生效"),
    ACTIVE("active", "已生效"),
    NORMAL_END("normal_end", "正常结束"),
    CANCELED("canceled", "已取消"),
    LOST_EFFECTIVENESS("lost_effectiveness","已失效");
    //编码
    private final String code;
    //信息
    private final String msg;

    private static Map<String, ContractOwnerStatusEnum> enumMap = new HashMap<>();
    static {
        ContractOwnerStatusEnum[] values = ContractOwnerStatusEnum.values();
        for (ContractOwnerStatusEnum value : values) {
            enumMap.put(value.getCode(), value);
        }
    }
    public static ContractOwnerStatusEnum getEnum(String num){
        return enumMap.get(num);
    }

    public static ContractOwnerStatusEnum getContractStatusEnumByCode(String code) {
        ContractOwnerStatusEnum[] contractStatusEnums = values();
        for (ContractOwnerStatusEnum contractStatusEnum : contractStatusEnums) {
            if (contractStatusEnum.code.equals(code)) {
                return contractStatusEnum;
            }
        }
        return null;
    }

    public static String getName(String code) {
        for (ContractOwnerStatusEnum c : ContractOwnerStatusEnum.values()) {
            if (c.getCode().equals(code)) {
                return c.msg;
            }
        }
        return null;
    }
}
